home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DLLCust_Files / LINAXON / GAINTANH.C < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  1.3 KB  |  43 lines

  1. // Dynamic link library implementation of BackTanhAxon with user gain control
  2.  
  3. #include "NSDLL.h"
  4.  
  5. /***********************************/
  6. /* Forward activation of component */
  7.  
  8. __declspec(dllexport) void performLinearAxon(
  9.     DLLData    *instance,    // Pointer to instance data
  10.     NSFloat    *data,         // Pointer to the layer of processing elements (PEs)
  11.     int     rows,        // Number of rows of PEs in the layer
  12.     int     cols,        // Number of columns of PEs in the layer
  13.     NSFloat    *bias,        // Pointer to the layer's bias vector, one for each PE
  14.     NSFloat    beta        // Slope gain scalar, same for all PEs
  15.     )
  16. {
  17.     int i, length=rows*cols;
  18.     NSFloat gain = getFloatParameter(instance, 2, 1);
  19.  
  20.     for (i=0; i<length; i++)
  21.         data[i] = gain*(NSFloat)tanh(beta*data[i] + bias[i]);
  22. }
  23.  
  24. /******************************************/
  25. /* Management of instance data (OPTIONAL) */
  26.  
  27. __declspec(dllexport) DLLData *allocLinearAxon(
  28.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  29.     int     rows,        // Number of rows of PEs in the layer
  30.     int     cols        // Number of columns of PEs in the layer
  31.     )
  32. {
  33.     DLLData *instance = allocDLLInstance(oldInstance);
  34.     setParameterName(instance, 2, 1, "Gain", FALSE);
  35.     setFloatParameter(instance, 2, 1, 1.0f, FALSE);
  36.     return instance;
  37. }
  38.  
  39. __declspec(dllexport) void freeLinearAxon(DLLData *instance)
  40. {
  41.     freeDLLInstance(instance);
  42. }
  43.